<?php
error_reporting(0);
ini_set('memory_limit', '1000M');
set_time_limit(0);


/** 
 *  mapper_7.php
 *      input:格式：mapred3输出 (json1\tjson2\t...)尤其要注意其中的weight字段
		1.对比上 	 weight>=35
		5.仅模糊对比上   1<=weight<35
		7.独立房源       weight=0   
		8.异常数据    （第一轮处理）
 *      handle:生成sql
 *      output:sql语句--INSERT INTO `house_sell_gov` VALUES ('1', ...);
 * @created 2016-03-09
   @updated 
 * @by lily
 */
$nu=0;
while (($line_json = fgets(STDIN)) !== false) {   //line_json=>source_url\tjson格式
    
    $line_json = trim($line_json);
    if (empty($line_json))
        continue;
	$aa=explode("\t", $line_json);
    //list ($unique_id,$min_price, $cnt, $deviation, $list_json) = explode("\t", $line_json);
	for($i=7;$i<count($aa);$i++){
		if($nu==0) {
			echo "INSERT INTO house_sell_gov_new(id,broker_id,house_price,house_desc,house_title,cityarea_id,cityarea2_id,house_floor,house_topfloor,house_toward,house_room,house_hall,house_toilet,house_kitchen,house_fitment,house_feature,house_built_year,use_area,owner_name,owner_phone,service_phone,house_support,created,updated,status,source,company_id,source_owner,app_url,wap_url,source_url,is_checked,click_num,refresh,house_type,house_totalarea,borough_id,borough_name,house_pic_unit,house_pic_layout,house_number,is_fill,is_contrast,broker_num,public_time,source_name,vr_url,video_url,unique_key,ctime,tag) VALUES";
			$nu=1;
		}  
		else{
			echo ",\n";
			$nu+=1;
		} 
		
		$one_dejson=json_decode($aa[$i],true); 
		
		if($aa[2]>1) $is_contrast=1;
		//elseif($one_dejson['weight']>=1&&$one_dejson['weight']<35) $is_contrast=5;
		else $is_contrast=7;
		
		echo " ('".$one_dejson['id']."','"
		.$one_dejson['broker_id']."','".$one_dejson['house_price']."','".
		str_replace("'","",str_replace("\\","",$one_dejson['house_desc']))."','".
		str_replace("'","",str_replace("\\","",$one_dejson['house_title']))."','".
		$one_dejson['cityarea_id']."','".$one_dejson['cityarea2_id']."','".
		$one_dejson['house_floor']."','".$one_dejson['house_topfloor']."','".
		$one_dejson['house_toward']."','".$one_dejson['house_room']."','".
		$one_dejson['house_hall']."','".$one_dejson['house_toilet']."','".
		$one_dejson['house_kitchen']."','".$one_dejson['house_fitment']."','".
		str_replace("'","",$one_dejson['house_feature'])."','".
		str_replace("'","",$one_dejson['house_built_year'])."','".
		$one_dejson['use_area']."','".
		str_replace("'","",$one_dejson['owner_name'])."','".
		$one_dejson['owner_phone']."','".
		$one_dejson['service_phone']."','".$one_dejson['house_support']."','".
		$one_dejson['created']."','".$one_dejson['updated']."','".
		$one_dejson['status']."','".$one_dejson['source']."','".
        $one_dejson['company_id']."','".
		$one_dejson['source_owner']."','".$one_dejson['app_url']."','".
		$one_dejson['wap_url']."','".$one_dejson['source_url']."','".
		$one_dejson['is_checked']."','".$one_dejson['click_num']."','".
		$one_dejson['refresh']."','".$one_dejson['house_type']."','".
		$one_dejson['house_totalarea']."','".$one_dejson['borough_id']."','".
		$one_dejson['borough_name']."','".$one_dejson['house_pic_unit']."','".
		$one_dejson['house_pic_layout']."','".$one_dejson['house_number']."','".
		$one_dejson['is_fill']."','".$is_contrast."','".
        $one_dejson['broker_num']."','".
		$one_dejson['public_time']."','".$one_dejson['source_name']."','".
$one_dejson['vr_url']."','".
$one_dejson['video_url']."','".
$one_dejson['unique_key']."','".
$one_dejson['ctime']."','".
$one_dejson['tag']."')";
		if($nu==19){
		    echo ";\n";
		    $nu=0;
		}
	} 	
}
echo ";\n";
?>

